package com.cqjybigscreen.controller;


import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.cqjybigscreen.pojo.dto.*;
import com.cqjybigscreen.pojo.vo.BoxTrendVO;
import com.cqjybigscreen.pojo.vo.BoxVolumeVO;
import com.cqjybigscreen.pojo.vo.LineNameSumMarVO;
import com.cqjybigscreen.pojo.vo.YearStatisticsVO;
import com.cqjybigscreen.service.AdsCqwlChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 四向通道汇总 前端控制器
 * </p>
 *
 * @author RaoChang
 */
@RestController
@RequestMapping("adsCqwlChannel")
@AllArgsConstructor
@Api(tags = "四向通道汇总")
public class AdsCqwlChannelController {
    private final AdsCqwlChannelService adsCqwlChannelService;

    /**
     * 大屏1左1
     * 获取箱量走势图
     * type: 1:近30天 2:最近3个月 3:最近1年
     */

    @ApiOperation(value = "大屏1左1-获取箱量走势图")
    @PostMapping("/getBoxPlotData")
    public List<BoxVolumeVO> getBoxVolume(@RequestBody BoxVolumeDTO dto) {
        if (CollectionUtils.isEmpty(dto.getDirection())) {
            dto.setDirection(Arrays.asList("西向", "北向", "南向", "东向"));
        }
        return adsCqwlChannelService.getBoxVolume(dto);
    }

    /**
     * 大屏1右1走向图
     * 同比环比都是上个月作为起点去比较
     */
    @GetMapping("/getBoxTrend")
    public List<BoxTrendVO> getBoxTrend() {
        //同比率数据
        //获取当前时间年份的开始时间LocalDate形式
        LocalDate startYear = LocalDate.of(LocalDate.now().getYear(), 1, 1);
        //获取今年年的结束时间
        LocalDate endYear = LocalDate.of(LocalDate.now().getYear() , 12, 31);

        //获取去年的开始时间
        LocalDate startLastYear = startYear.minusYears(1);

        //获取去年的结束时间
        LocalDate endLastYear = LocalDate.now().minusYears(1);

        //环比率数据
        //获取本月开始时间
        LocalDate startMonth = LocalDate.now().minusMonths(1).with(TemporalAdjusters.firstDayOfMonth());

        //获取本月结束时间
        LocalDate endMonth = LocalDate.now().minusMonths(1).with(TemporalAdjusters.lastDayOfMonth());

        //获取上个月开始时间
        LocalDate startLastMonth = LocalDate.now().minusMonths(2).with(TemporalAdjusters.firstDayOfMonth());

        //获取上个月结束时间
        LocalDate endLastMonth = LocalDate.now().minusMonths(2).with(TemporalAdjusters.lastDayOfMonth());
        return adsCqwlChannelService.getBoxTrend(startYear, endYear, startLastYear, endLastYear, startMonth, endMonth, startLastMonth, endLastMonth);
    }

    /**
     * 大屏1右2精品路线列表查询
     */
    @PostMapping("/premiumRouteList")
    public List<BoxVolumeVO> premiumRouteList(@RequestBody BoxTrendDto dto) {
        return adsCqwlChannelService.premiumRouteList(dto);
    }

    /**
     * 大屏1右2精品路线详情
     * 目前按照传入终点,查询终点站是传入值的所有路线信息
     */
    @PostMapping("/premiumRouteDetails")
    public List<BoxVolumeVO> premiumRouteDetails(@RequestBody RouteDTO dto) {
        //参数校验
        if (dto.getDestinationStation() == null) {
            return null;
        }
        return adsCqwlChannelService.premiumRouteDetails(dto);
    }

    /**
     * 大屏1右3 运输方式
     */
    @GetMapping("/getTransportationMode")
    public List<BoxVolumeVO> getTransportationMode() {
        return adsCqwlChannelService.getTransportationMode();
    }

    /**
     * 大屏1中间年度统计
     */
    @PostMapping("/getYearStatistics")
    public List<YearStatisticsVO> getYearStatistics(@RequestBody BoxTrendDto dto) {
        return adsCqwlChannelService.getYearStatistics(dto);
    }


    /**
     * 物流大屏2左1箱量走势-根据目的地站查询
     */
    @PostMapping("boxPlotDataWithRoute")
    public List<DataGroupDTO> boxPlotDataWithRoute(@RequestBody BoxVolumeDTO dto) {

        return adsCqwlChannelService.boxPlotDataWithRoute(dto);
    }

    /**
     * 物流大屏2左2 近半年货运量同比环比-根据目的地站查询
     */
    @PostMapping("getBoxTrendWithRoute")
    public List<Map<String, Object>> getBoxTrendWithRoute(@RequestBody RouteDTO dto) {
        return adsCqwlChannelService.getBoxTrendWithRoute(dto);
    }

    /**
     * 物流大屏2中间线路
     */
    @PostMapping("getMapList")
    public LineNameSumMarVO getMapList(@RequestBody PortStationDTO dto) {
        return adsCqwlChannelService.getMapList(dto);
    }

    /**
     * 获取货物排行榜
     */
    @PostMapping("/getGoodsRank")
    public List<BoxVolumeVO> getGoodsRanking(@RequestBody RouteDTO dto) {

        return adsCqwlChannelService.getGoodsRanking(dto);
    }

}
